package com.tdam2011.grupo06.control;

import java.util.GregorianCalendar;

import com.tdam2011.grupo06.model.ItemConectividad;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

public class ConnectivityReceiver extends BroadcastReceiver 
{
	@Override
	public void onReceive(Context context, Intent intent) 
	{
		/*boolean noConnectivity = intent.getBooleanExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY, false);
		String reason = intent.getStringExtra(ConnectivityManager.EXTRA_REASON);
		boolean isFailover = intent.getBooleanExtra(ConnectivityManager.EXTRA_IS_FAILOVER, false);*/
		
		NetworkInfo currentNetworkInfo = (NetworkInfo) intent.getParcelableExtra(ConnectivityManager.EXTRA_NETWORK_INFO);
		
		int tipo;
		int accion;
		
		
		
		if(currentNetworkInfo != null && currentNetworkInfo.isConnectedOrConnecting()) {accion = ItemConectividad.tipoConecto;}
		else {accion = ItemConectividad.tipoDesconecto;}
		
		if(currentNetworkInfo != null && ConnectivityManager.TYPE_WIFI==currentNetworkInfo.getType()){tipo = ItemConectividad.tipoWIFI;}
		else {tipo = ItemConectividad.tipo3G;}
		
		DatabaseHelper db = DatabaseHelper.getInstance(context);
		ItemConectividad item = new ItemConectividad(0,tipo,GregorianCalendar.getInstance().getTime(),accion);
		
		db.addItemConectividad(item);
		
		/*Log.d("Apli", "Booleano conectividad: " + noConnectivity);
		
		Log.d("Apli", "String razon: " + reason);
		
		Log.d("Apli", "Booleano failober: " + isFailover);
		
		Log.d("Apli", "Booleano disponible: " + currentNetworkInfo.isAvailable());
		
		Log.d("Apli", "Booleano conectado: " + currentNetworkInfo.isConnected());
		
		Log.d("Apli", "Booleano conectando: " + currentNetworkInfo.isConnectedOrConnecting());
		
		Log.d("Apli", "Coneccion actual tipo: " + currentNetworkInfo.getTypeName());
		
		Log.d("Apli", "Coneccion actual subtipo: " + currentNetworkInfo.getSubtypeName());*/
	}
}
